package net.zjitc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.zjitc.entity.Apply;
import net.zjitc.entity.Mycollect;
import net.zjitc.entity.Recruit;
import net.zjitc.entity.VO.RecruitVo;
import net.zjitc.mapper.*;
import net.zjitc.service.IRecruitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @auther 郭梦婷
 * @create 2022-05-05 14:07:31
 * @describe 服务实现类
 */
@Service
@Transactional
public class RecruitServiceImpl extends ServiceImpl<RecruitMapper, Recruit> implements IRecruitService {
    @Autowired
    private RecruitMapper recruitMapper;

    @Autowired
    private EducationMapper educationMapper;
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private MycollectMapper mycollectMapper;
    @Autowired
    private ApplyMapper applyMapper;

    @Override
    public Page<RecruitVo> getRecruit(String querystring, Integer pagenum, Integer pagesize) {
        Page<RecruitVo> page=new Page<>(pagenum,pagesize);
        if (querystring.length()==0){
            page = recruitMapper.selectallRecruit(page,null);
        }else {
            page = recruitMapper.selectRecruit(page, querystring);
        }

        return page;
    }

    @Override
    public int deleteById(int id) {
        //删除收藏岗位
        QueryWrapper<Mycollect> wrapper=new QueryWrapper<>();
        wrapper.eq("recruitid",id);
        mycollectMapper.delete(wrapper);
        //删除申请岗位
        QueryWrapper<Apply> wrapper1=new QueryWrapper<>();
        wrapper1.eq("recruitid",id);
        applyMapper.delete(wrapper1);

        int i = recruitMapper.deleteById(id);
        return i;
    }

    @Override
    public RecruitVo selectById(Integer id) {
        RecruitVo recruit = recruitMapper.selectRecruitVoById(id);

        return recruit;
    }

    @Override
    public Page<RecruitVo> SearchRecruid(String querystring, Integer eduid, String cateids, String placeids, Integer pagenum, Integer pagesize) {
        Page<RecruitVo> page=new Page<>(pagenum,pagesize);
        Integer placeid=0,cateid=0;
        if (cateids.length()!=0){
            cateid = Integer.parseInt(cateids.split(",")[2]);

        }
        if (placeids.length()!=0){
            placeid = Integer.parseInt(placeids.split(",")[2]);
        }
        if (eduid==null){
            eduid=9;
        }

        page = recruitMapper.SearchRecruid(page, querystring,eduid,placeid,cateid);
        return page;
    }

    @Override
    public Page<RecruitVo> getRecruitByComId(Integer comid, String querystring, Integer pagenum, Integer pagesize) {
        Page<RecruitVo> page=new Page<>(pagenum,pagesize);
        page=recruitMapper.getRecruitByComId(page,comid,querystring);

        return page;
    }

    @Override
    public Page<RecruitVo> SearchRecruidByComId(Integer eduid, String cateids, Integer pagenum, Integer pagesize, int comid) {
        Page<RecruitVo> page=new Page<>(pagenum,pagesize);
        Integer cateid=0;
        if (cateids.length()!=0){
            cateid = Integer.parseInt(cateids.split(",")[2]);
        }
        if (eduid==null){
            eduid=9;
        }
        page=recruitMapper.SearchRecruidByComId(page,cateid,eduid,comid);
        return page;
    }
}
